<template>
	<div class="app-container">
		<el-tabs type="card" @tab-click="handleClick" v-model="activeName">
			<el-tab-pane label="最终结果" name="first" v-loading="loading1" element-loading-text="计算中...">
				<LoessPlateauForm />
			</el-tab-pane>
			<el-tab-pane label="中间结果" name="second">
				<el-table v-loading="loading" :data="middleResultList">
					<el-table-column label="使用模型" align="center" prop="modelType">
						<template #default="scope">
							<div v-if="scope.row.modelType == 1">层次分析法模型</div>
							<div v-if="scope.row.modelType == 2">黄土高原模型</div>
							<div v-if="scope.row.modelType == 3">指数模型</div>
							<div v-if="scope.row.modelType == 4">逻辑斯蒂模型</div>
							<div v-if="scope.row.modelType == 5">Newmark模型</div>
						</template>
					</el-table-column>
					<el-table-column label="生成时间" align="center" prop="evaluateTime" />
					<el-table-column label="生成人" align="center" prop="evaluateUserName" />

					<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
						<template #default="scope">
							<el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
							<el-button type="text" @click="handleReplace(scope.row)">替换为最终结果</el-button>
							<el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script setup name="loessPlateau">
import { getDzzhTaskModel, replaceFinalResult, delDzzhTaskModel } from "@/api/slideAssess/loessPlateau";
import LoessPlateauForm from './loessPlateauForm.vue'

const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance();
const activeName = ref("first");
const middleResultList = ref([]);
const loading = ref(false);
const loading1 = ref(false);


/** 删除按钮操作 */
function handleDelete(row) {
	const dtmId = row.dtmId;
	proxy.$modal.confirm('是否确认删除？').then(function () {
	}).then(() => {
		delDzzhTaskModel({ "dtmId": dtmId }).then(response => {
			proxy.$modal.msgSuccess("删除成功");
			getList();
		});
	}).catch(() => { });
}
//获取中间结果列表
function getList() {
	loading.value = true;
	getDzzhTaskModel({ "taskId": route.query.taskId }).then(response => {
		middleResultList.value = response.data;
		loading.value = false;
	});
}
//修改
function handleEdit(row) {
	activeName.value = "first";
	if (row.modelType == "1") {
		//层次分析法
		router.push({
			path: "/analysisAssess/levelAnalyseForm",
			query: {
				taskId: row.taskId,
				modelType: row.modelType,
				taskDistrict: row.taskDistrict,
				metaTitle: "修改层次分析法模型中间结果",
				dtmId: row.dtmId
			}
		})
	}
	if (row.modelType == "2") {
		//黄土高原
		router.push({
			path: "/analysisAssess/loessPlateauForm",
			query: {
				taskId: row.taskId,
				modelType: row.modelType,
				taskDistrict: row.taskDistrict,
				metaTitle: "修改黄土高原模型中间结果",
				dtmId: row.dtmId
			}
		})
	}
	if (row.modelType == "3") {
		router.push({
			path: "/analysisAssess/indexModelForm",
			query: {
				taskId: route.query.taskId,
				modelType: row.modelType,
				taskDistrict: route.query.taskDistrict,
				metaTitle: "修改指数模型中间结果",
				dtmId: row.dtmId
			}
		})
	}
	if (row.modelType == "4") {
		router.push({
			path: "/analysisAssess/logistiForm",
			query: {
				taskId: route.query.taskId,
				modelType: row.modelType,
				taskDistrict: route.query.taskDistrict,
				metaTitle: "修改逻辑斯蒂模型中间结果",
				dtmId: row.dtmId
			}
		})
	}
	if (row.modelType == "5") {
		router.push({
			path: "/analysisAssess/newMarkForm",
			query: {
				taskId: route.query.taskId,
				modelType: row.modelType,
				taskDistrict: route.query.taskDistrict,
				metaTitle: "修改newMark模型中间结果",
				dtmId: row.dtmId
			}
		})
	}
}
//替换为最终结果
function handleReplace(row) {
	var dtmId = row.dtmId;
	var taskId = row.taskId;
	var flag = "";
	proxy.$confirm('请选择是否将被替换的结果存为中间结果选择“否”，被替换的结果作废', '系统提示',
		{ confirmButtonText: '是', cancelButtonText: '否', type: 'warning' }).then(function () {
		}).then(() => {
			flag = "1"
			replaceFinalResult({ "dtmId": dtmId, "flag": flag, "taskId": taskId }).then(response => {
				proxy.$modal.msgSuccess(response.message);
			});
		}).catch(() => {
			flag = "0"
			replaceFinalResult({ "dtmId": dtmId, "flag": flag, "taskId": taskId }).then(response => {
				proxy.$modal.msgSuccess(response.message);
			});
		});
}
//切换标签页
function handleClick(tab, event) {
	if (tab.props.name == 'second') {
		getList()
	}
}
</script>
<style scoped lang="scss">
.tab-title {
	font-size: 16px;
	font-weight: bold;
	border-left: 4px solid #0D9AFF;
	font-family: PingFangSC-Medium;
	padding-left: 10px;
	margin: 10px 0 10px;
}

.line {
	text-align: center;
}

table td {
	border: 1px solid #c6c6c6;
	padding: 5px;
}
</style>
<style>
.tool-tip {
	max-width: 400px;
}
</style>